package com.example.demo.common;

import lombok.Data;

/**
 * @author liye
 * @date 2025/10/9 16:35
 * @description:  建议  更新这个R结果集     ：    R结果集和结果枚举 进行统一封装
 */
@Data
public class R<T> {

    private Integer code;//状态码
    private String msg;//信息
    private T data;//数据
    private Long  count;//总条数

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public void setData(T data) {
        this.data = data;
    }
        //方便直接调用
        public static <T> R<T> success(T data){
            R<T> r = new R<>();
            r.setCode(0);
            r.setData(data);
            return r;
        }
    public static <T> R<T> success(T data,Long count){
        R<T> r = new R<>();
        r.setCode(0);
        r.setData(data);
        r.setCount(count);
        r.setMsg("操作成功");
        return r;
    }
    public static <T> R<T> success(){
        R<T> r = new R<>();
        r.setCode(0);
        r.setMsg("操作成功");
        return r;
    }
    public static <T> R<T> success(T data,String msg){
        R<T> r = new R<>();
        r.setCode(0);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }
    public static <T> R<T> error(){
        R<T> r = new R<>();
        r.setCode(500);
        r.setMsg("操作失败");
        return r;
    }
    public static <T> R<T> error(String msg){
        R<T> r = new R<>();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }
    public static <T> R<T> error(Integer code,String msg){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }



}
